# Maintainer: Yusuke Sasaki <yusuke.sasaki.nuem@gmail.com>

_realname=msgpack-c
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.0.0
pkgrel=1
pkgdesc="MessagePack implementation for C and C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/msgpack/msgpack-c"
license=('spdx:BSL-1.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-gtest"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-zlib"
             "${MINGW_PACKAGE_PREFIX}-cc")
depends=()
source=("https://github.com/msgpack/msgpack-c/releases/download/c-${pkgver}/msgpack-c-${pkgver}.tar.gz")
sha256sums=('eb6d77f32dbaaae9174d96cacfe02af30bf1ea329c45018074cd95ac6e6fa6e5')

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL='-DCMAKE_INSTALL_PREFIX=' \
    ${MINGW_PREFIX}/bin/cmake \
      -G "Ninja" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      ${extra_config} \
      -DMSGPACK_BUILD_EXAMPLES=OFF \
      -DMSGPACK_BUILD_TESTS=OFF \
      ../msgpack-c-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/ctest || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
  install -Dm644 ${srcdir}/msgpack-c-${pkgver}/LICENSE_1_0.txt ${okgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE_1_0.txt
}
